package 线性查找;

/*
*
* 遍历线性查找target
*
* */
public class LinearSearch {
    private LinearSearch(){}
    public static <E> int search(E [] arr, E target ){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals(target)){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Student student1 = new Student("sunlei1");
        Student student2 = new Student("sunlei2");
        Student student3 = new Student("sunleI2");
        Student arr [] = {student1, student2};
        int search = LinearSearch.search(arr, student3);
        System.out.println(search);

    }
}
